package com.bwhx.eruler.dao.casdilly.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bwhx.eruler.bean.casdilly.BodyItem;
import com.bwhx.eruler.bean.casdilly.ClothesType;
import com.bwhx.eruler.bean.casdilly.Contract;
import com.bwhx.eruler.dao.casdilly.ClothesTypeDAO;
import com.bwhx.eruler.dao.impl.BaseDaoImpl;

@Repository
public class ClothesTypeDAOImpl extends BaseDaoImpl<ClothesType> implements ClothesTypeDAO {

	public ClothesTypeDAOImpl() {
		this.setNs("com.bwhx.eruler.mapper.casdilly.ClothesTypeMapper.");
	}

	@Override
	public List<ClothesType> findByTypeCPIDSerial(String contractID) {
		List<ClothesType> selectList = getSqlSession().selectList(this.getNs() + "findByTypeCPIDSerial", contractID);

		for (ClothesType clothesType : selectList) {
			List<BodyItem> selectList2 = getSqlSession().selectList(this.getNs() + "getBodyItem",
					clothesType.getTypeItemsStr().split(","));
			clothesType.setTypeItems(selectList2);
		}

		return selectList;
	}

	@Override
	public List<ClothesType> findByTypeCategory(Integer category) {

		return getSqlSession().selectList(this.getNs() + "findByTypeCategory", category);
	}

	@Override
	public List<ClothesType> findByIds(List<String> asList) {
		return getSqlSession().selectList(this.getNs() + "findByIds", asList);
	}

	@Override
	public List<ClothesType> findByCTNameAndTypeAndProjectSerial(ClothesType ct) {
		return getSqlSession().selectList(this.getNs() + "findByCTNameAndTypeAndProjectSerial", ct);
	}

	@Override
	public List<ClothesType> listByContract(Contract contract) {

		List<ClothesType> clothesTypeList = getSqlSession().selectList(this.getNs() + "listByContract", contract);

		return clothesTypeList;
	}

	@Override
	public ClothesType findByID(ClothesType ct) {
		return getSqlSession().selectOne(this.getNs() + "findByID", ct);
	}

	@Override
	public void relateClothes(ClothesType ct) {
		this.getSqlSession().update(this.getNs() + "relateClothes", ct);
	}

	@Override
	public void deleteById(ClothesType clothesType) {
		this.getSqlSession().update(this.getNs() + "deleteById", clothesType);
	}

	@Override
	public boolean saveDisplayOrder(List<ClothesType> typies) {
		return this.getSqlSession().update(this.getNs() + "updateDisplayOrder", typies) > 0;
	}

	@Override
	public int deleteByTypeCPIDSerial(ClothesType clothestype) {
		return this.getSqlSession().update(this.getNs() + "deleteByTypeCPIDSerial", clothestype);
		
	}

	@Override
	public List<ClothesType> findByClothesTypeBycPIDSerial(ClothesType ct) {
		return this.getSqlSession().selectList(this.getNs() + "findByClothesTypeBycPIDSerial", ct);
	}

}
